package com.lv.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;

import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;

import springfox.documentation.builders.RequestHandlerSelectors;

import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


/**
 * Created with IntelliJ IDEA.
 * Swagger配置文件
 * @Author: 凉薄
 * @Date: 2022/01/05/21:47
 * @Description:
 */
@Configuration
@EnableOpenApi
@EnableWebMvc
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment env){
        Profiles profiles=Profiles.of("prod");
        boolean enable=env.acceptsProfiles(profiles);
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                //  定义是否开启swagger，false为关闭，可以通过变量控制,默认为true
                .enable(true)
                .select()
                //RequestHandlerSelectors 配置要扫描接口的方式
                .apis(RequestHandlerSelectors.basePackage("com.lv.controller"))
                //paths() 过滤什么路径
//                .paths(PathSelectors.ant("/wang/**"))
                .build();
    }
    private ApiInfo apiInfo(){
        //作者信息
        return new ApiInfoBuilder()
                //标题
                .title("Lv 的Swagger")
                //版本
                .version("6.6.6")
                //描述
                .description("API文档")
                //团队地址
                .termsOfServiceUrl("www.baidu.com")
                //许可证
                .license("Lv版权所有")
                //联系信息
                .contact(new Contact("凉薄","www.baidu.com","lvshihao260@qq.com"))
                .build();
    }

}
